package com.itheima.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService{

    @Autowired
    private MemberDao memberDao;


    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public void edit(Member member) {
        memberDao.edit(member);
    }

    @Override
    public List<Member> findAll() {
        List<Member> list = memberDao.findAll();
        return list;
    }

    @Override
    public Member findById(Integer id) {
        Member member = memberDao.findByParam(id);
        return member;
    }

    @Override
    public void del(Integer id) {
        memberDao.delById(id);
    }

    @Override
    public List<Integer> findMemberCountByMonth(List<String> mouth) {
         List<Integer> list = new ArrayList<>();
         for(String m:mouth){
             m = m + ".31";
             Integer count = memberDao.findMemberCountBeforeDate(m);
             list.add(count);
         }
        return list;
    }

    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByParam(telephone);
    }

    @Override
    public void logout(String telephone) {
        memberDao.logout(telephone);
    }
}
